package com.hua.ui;

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class GetStringWindow extends JDialog {
	private JTextField textField;
	private String getText = null;

	public GetStringWindow(String name, String content, String tip) {
		setModal(true);
		setTitle(name);

		getContentPane().setLayout(null);

		JLabel lblNewLabel = new JLabel(content);
		lblNewLabel.setFont(new Font("Alimama ShuHeiTi", Font.PLAIN, 15));
		lblNewLabel.setBounds(14, 13, 400, 26);
		getContentPane().add(lblNewLabel);

		textField = new JTextField();
		textField.setText(tip);
		textField.setForeground(SystemColor.inactiveCaption);
		textField.setFont(new Font("Alimama ShuHeiTi", Font.PLAIN, 16));
		textField.setColumns(10);
		textField.setBounds(14, 52, 449, 32);
		getContentPane().add(textField);

		JButton btnNewButton = new JButton("完成");
		btnNewButton.setBounds(365, 97, 98, 32);
		getContentPane().add(btnNewButton);

		pack();
		setSize(587, 209); // 设置窗口大小
		setBounds(700, 400, 515, 200);

		btnNewButton.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				String text = textField.getText();
				if (text != null && !text.equals("")) {
					getText = text;
				}
				dispose(); // 销毁窗口
			}
		});
		
		textField.addActionListener(e -> {
			String text = textField.getText();
			if (text != null && !text.equals("")) {
				getText = text;
			}
			dispose(); // 销毁窗口
		});

		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				getText = null;
				
			}
		});
	}

	public String getGetText() {
		return getText;
	}
}
